<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>L2LB: nlb-driver.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Gerado por Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Página&nbsp;principal</span></a></li>
      <li><a href="annotated.html"><span>Estruturas&nbsp;de&nbsp;dados</span></a></li>
      <li class="current"><a href="files.html"><span>Ficheiros</span></a></li>
    </ul>
  </div>
<h1>nlb-driver.c</h1><a href="nlb-driver_8c.html">Ir para a documentação deste ficheiro.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00007"></a>00007 <span class="preprocessor">#include &lt;linux/kernel.h&gt;</span>
<a name="l00008"></a>00008 <span class="preprocessor">#include &lt;linux/module.h&gt;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &lt;linux/init.h&gt;</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;linux/skbuff.h&gt;</span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;linux/netfilter_ipv4.h&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;linux/ip.h&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;linux/in.h&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;linux/if_ether.h&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;linux/inetdevice.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;linux/netdevice.h&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;linux/etherdevice.h&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;linux/vmalloc.h&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;linux/kthread.h&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;linux/delay.h&gt;</span> 
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;linux/net.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;linux/socket.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;linux/errno.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;linux/types.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;linux/delay.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;linux/moduleparam.h&gt;</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="preprocessor">#ifndef DOXYGEN_SHOULD_SKIP_THIS</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="comment">/* Nome do modulo do kernel */</span>
<a name="l00030"></a>00030 <span class="preprocessor">#define MODULE_NAME "L2LB"</span>
<a name="l00031"></a>00031 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span>
<a name="l00033"></a>00033 <span class="preprocessor">#include "<a class="code" href="utils_8h.html" title="Funções utilitárias.">utils.h</a>"</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include "<a class="code" href="cluster_8h.html" title="Arquivo responsável por gerenciar (incluir/remover/buscar) os servidores do cluster...">cluster.h</a>"</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="hash-afinidades_8h.html" title="Arquivo responsável por gerenciar as afinidades entre os clientes e os servidores...">hash-afinidades.h</a>"</span>
<a name="l00036"></a>00036 <span class="preprocessor">#include "<a class="code" href="socket_8h.html" title="Métodos para enviar/receber mensagens via socket.">socket.h</a>"</span>
<a name="l00037"></a>00037 <span class="preprocessor">#include "<a class="code" href="heartbeat_8h.html" title="Arquivo responsável por enviar/receber mensagens de heartbeat, para detecção de...">heartbeat.h</a>"</span>
<a name="l00038"></a>00038 <span class="preprocessor">#include "<a class="code" href="thread_8h.html" title="Arquivo responsável pela criação de threads.">thread.h</a>"</span>
<a name="l00039"></a>00039 <span class="preprocessor">#include "<a class="code" href="interface_8h.html" title="Arquivo responsável por receber e interpretar comandos de administração do L2LB...">interface.h</a>"</span>
<a name="l00040"></a>00040 <span class="preprocessor">#include "<a class="code" href="netfilter_8h.html" title="Arquivo responsável por interceptar as requisições usando a API Netfilter.">netfilter.h</a>"</span>
<a name="l00041"></a>00041 
<a name="l00042"></a>00042 <span class="preprocessor">#ifndef DOXYGEN_SHOULD_SKIP_THIS</span>
<a name="l00043"></a>00043 <span class="preprocessor"></span>MODULE_DESCRIPTION(<span class="stringliteral">"Layer 2 Load Balancing Kernel Module"</span>);
<a name="l00044"></a>00044 MODULE_AUTHOR(<span class="stringliteral">"Daniel Gomes Silveira (dan_gs@im.ufba.br)"</span>);
<a name="l00045"></a>00045 MODULE_LICENSE(<span class="stringliteral">"$LICENSE$"</span>);
<a name="l00046"></a>00046 <span class="preprocessor">#endif</span>
<a name="l00047"></a>00047 <span class="preprocessor"></span>
<a name="l00051"></a><a class="code" href="nlb-driver_8c.html#312f6a236fcec7f8803e170412fb3f86">00051</a> <span class="keyword">static</span> <span class="keywordtype">char</span> <a class="code" href="nlb-driver_8c.html#312f6a236fcec7f8803e170412fb3f86" title="Interface de rede do cluster que sera gerenciada pelo L2LB.">dev</a>[9];
<a name="l00052"></a>00052 
<a name="l00056"></a><a class="code" href="nlb-driver_8c.html#c8f175c78fae68f5348eab7bcc8ca54b">00056</a> <span class="keyword">static</span> <span class="keywordtype">char</span> <a class="code" href="nlb-driver_8c.html#c8f175c78fae68f5348eab7bcc8ca54b" title="IP virtual do cluster.">ip</a>[17];
<a name="l00057"></a>00057 
<a name="l00058"></a>00058 <span class="preprocessor">#ifndef DOXYGEN_SHOULD_SKIP_THIS</span>
<a name="l00059"></a>00059 <span class="preprocessor"></span>module_param_string(<a class="code" href="nlb-driver_8c.html#312f6a236fcec7f8803e170412fb3f86" title="Interface de rede do cluster que sera gerenciada pelo L2LB.">dev</a>, <a class="code" href="nlb-driver_8c.html#312f6a236fcec7f8803e170412fb3f86" title="Interface de rede do cluster que sera gerenciada pelo L2LB.">dev</a>, <span class="keyword">sizeof</span>(<a class="code" href="nlb-driver_8c.html#312f6a236fcec7f8803e170412fb3f86" title="Interface de rede do cluster que sera gerenciada pelo L2LB.">dev</a>), 0);
<a name="l00060"></a>00060 module_param_string(<a class="code" href="nlb-driver_8c.html#c8f175c78fae68f5348eab7bcc8ca54b" title="IP virtual do cluster.">ip</a>, <a class="code" href="nlb-driver_8c.html#c8f175c78fae68f5348eab7bcc8ca54b" title="IP virtual do cluster.">ip</a>, <span class="keyword">sizeof</span>(<a class="code" href="nlb-driver_8c.html#c8f175c78fae68f5348eab7bcc8ca54b" title="IP virtual do cluster.">ip</a>), 0);
<a name="l00061"></a>00061 <span class="preprocessor">#endif</span>
<a name="l00062"></a>00062 <span class="preprocessor"></span>
<a name="l00080"></a><a class="code" href="nlb-driver_8c.html#a6bb443824ee776be4a7a888f204b1d2">00080</a> <span class="keywordtype">int</span>     <a class="code" href="nlb-driver_8c.html#a6bb443824ee776be4a7a888f204b1d2" title="Wrapper do metodo dev.hard_start_xmit_old() implementado pelo driver rede responsavel...">dev_cluster_hard_start_xmit_new</a> (<span class="keyword">struct</span> sk_buff *skb, <span class="keyword">struct</span> net_device *<a class="code" href="nlb-driver_8c.html#312f6a236fcec7f8803e170412fb3f86" title="Interface de rede do cluster que sera gerenciada pelo L2LB.">dev</a>)
<a name="l00081"></a>00081 {
<a name="l00082"></a>00082         <span class="keyword">struct </span>ethhdr *eth;
<a name="l00083"></a>00083         
<a name="l00084"></a>00084         eth = (<span class="keyword">struct </span>ethhdr *)skb-&gt;data;
<a name="l00085"></a>00085          
<a name="l00086"></a>00086         memcpy(&amp;eth-&gt;h_source, &amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#5c014dc4806dfdcc72ddcdfff23231ae">mac_response</a>, ETH_ALEN);
<a name="l00087"></a>00087         
<a name="l00088"></a>00088         <span class="keywordflow">return</span> <a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#088588314045ccef65ac5c6b72d5e37d">hard_start_xmit_old</a>(skb, dev);
<a name="l00089"></a>00089 }
<a name="l00090"></a>00090 
<a name="l00100"></a><a class="code" href="nlb-driver_8c.html#58c1436a949928f231d221233cd6c274">00100</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="nlb-driver_8c.html#58c1436a949928f231d221233cd6c274" title="Incializa o modulo do kernel.">nlb_init_module</a>(<span class="keywordtype">void</span>)
<a name="l00101"></a>00101 {       
<a name="l00102"></a>00102         <span class="comment">//Inicializa a estruturas do cluster</span>
<a name="l00103"></a>00103         <span class="keywordflow">if</span>(<a class="code" href="cluster_8h.html#33d0ab81e5ab7cf05146cead194236b7" title="Inicializa a estrutura my_cluster.">init_cluster</a>(<a class="code" href="nlb-driver_8c.html#312f6a236fcec7f8803e170412fb3f86" title="Interface de rede do cluster que sera gerenciada pelo L2LB.">dev</a>, <a class="code" href="nlb-driver_8c.html#c8f175c78fae68f5348eab7bcc8ca54b" title="IP virtual do cluster.">ip</a>, &amp;<a class="code" href="nlb-driver_8c.html#a6bb443824ee776be4a7a888f204b1d2" title="Wrapper do metodo dev.hard_start_xmit_old() implementado pelo driver rede responsavel...">dev_cluster_hard_start_xmit_new</a>) &lt; 0)
<a name="l00104"></a>00104                 <span class="keywordflow">return</span> -1;      
<a name="l00105"></a>00105         
<a name="l00106"></a>00106         <span class="comment">//Inicializa a interface com o modulo do kernel atraver de /proc/nlb</span>
<a name="l00107"></a>00107         <span class="keywordflow">if</span>(<a class="code" href="interface_8h.html#65a3f35a0907ebf967e1f54265516827" title="Inicializa a interface do cluster criando o arquivo /proc/nlb.">init_proc_interface</a>() &lt; 0)
<a name="l00108"></a>00108                 <span class="keywordflow">return</span> -1;
<a name="l00109"></a>00109         
<a name="l00110"></a>00110         <a class="code" href="utils_8h.html#b0f950c72d35e5d0cffbf735b7123284" title="Imprime um endereço MAC no log do kernel.">printk_mac_addr</a>((u8 *)&amp;<a class="code" href="cluster_8h.html#1917b2709741dea7ce5cf6ea441686ed" title="Cluster.">my_cluster</a>.<a class="code" href="structcluster.html#5c014dc4806dfdcc72ddcdfff23231ae">mac_response</a>);
<a name="l00111"></a>00111         
<a name="l00112"></a>00112         <span class="comment">//Inicializa a tabela HASH de afinidades</span>
<a name="l00113"></a>00113         <a class="code" href="hash-afinidades_8h.html#b8049b9214af4294d4fcd4fdd29b28e1" title="Cria a tabela HASH de afinidade.">hash_init</a>();
<a name="l00114"></a>00114         
<a name="l00115"></a>00115         <span class="comment">//Inicializa a Thread que ira gerenciar a comunicacao entre os servidores do cluster</span>
<a name="l00116"></a>00116         <span class="comment">//via socket em uma VLAN privada.</span>
<a name="l00117"></a>00117         <a class="code" href="thread_8h.html#6e122a678ab2f0b6f13a266c214813eb" title="Cria threads para enviar e receber mensagens UDP.">nlb_thread_init</a>();
<a name="l00118"></a>00118         
<a name="l00119"></a>00119         <span class="comment">//Registra os HOOKS do Netfilter</span>
<a name="l00120"></a>00120         <span class="keywordflow">if</span>(<a class="code" href="netfilter_8h.html#bf19d764f0af6d861e95cb83707589a7" title="Inicializa a interceptação dos pacotes com o Netfilter.">nlb_netfilter_init</a>() &lt; 0) 
<a name="l00121"></a>00121                 <span class="keywordflow">return</span> -1;
<a name="l00122"></a>00122         
<a name="l00123"></a>00123         printk( KERN_ALERT MODULE_NAME <span class="stringliteral">": Module nlb init\n"</span> );
<a name="l00124"></a>00124         <span class="keywordflow">return</span> 0;
<a name="l00125"></a>00125 }
<a name="l00126"></a>00126 
<a name="l00130"></a><a class="code" href="nlb-driver_8c.html#252459a2361783e1bd1da46b46c2bdf6">00130</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="nlb-driver_8c.html#252459a2361783e1bd1da46b46c2bdf6" title="Desregistra o modulo.">nlb_exit_module</a>(<span class="keywordtype">void</span>)
<a name="l00131"></a>00131 {
<a name="l00132"></a>00132         <a class="code" href="cluster_8h.html#aa5aa80302607600a63f6b78dc842b75" title="Finaliza o cluster.">nlb_cluster_exit</a>();
<a name="l00133"></a>00133         
<a name="l00134"></a>00134         <span class="comment">//Libera a tabela de afinidades</span>
<a name="l00135"></a>00135         <a class="code" href="hash-afinidades_8h.html#250cf847fac6e25b8e87545604a1ba60" title="Destroy a tabela de HASH.">hash_exit</a>();
<a name="l00136"></a>00136         
<a name="l00137"></a>00137         <span class="comment">//Remove o hook do Netfilter</span>
<a name="l00138"></a>00138         <a class="code" href="netfilter_8h.html#dfb4739620e1a1d113735757982d0d7e" title="Interrompe a interceptação dos pacotes com o Netfilter.">nlb_netfilter_exit</a>();
<a name="l00139"></a>00139         
<a name="l00140"></a>00140         <span class="comment">//Finaliza a Thread do socket</span>
<a name="l00141"></a>00141         <a class="code" href="thread_8h.html#7c8900a7756e71bec1ed910214a1bfd9" title="Encerra os threads.">nlb_thread_exit</a>();
<a name="l00142"></a>00142         
<a name="l00143"></a>00143         printk( KERN_ALERT MODULE_NAME <span class="stringliteral">": Module nlb exit\n"</span> );
<a name="l00144"></a>00144 }
<a name="l00145"></a>00145 
<a name="l00146"></a>00146 <span class="preprocessor">#ifndef DOXYGEN_SHOULD_SKIP_THIS</span>
<a name="l00147"></a>00147 <span class="preprocessor"></span>
<a name="l00151"></a>00151 module_init(<a class="code" href="nlb-driver_8c.html#58c1436a949928f231d221233cd6c274" title="Incializa o modulo do kernel.">nlb_init_module</a>);
<a name="l00152"></a>00152 module_exit(<a class="code" href="nlb-driver_8c.html#252459a2361783e1bd1da46b46c2bdf6" title="Desregistra o modulo.">nlb_exit_module</a>);
<a name="l00153"></a>00153 <span class="preprocessor">#endif</span>
<a name="l00154"></a>00154 <span class="preprocessor"></span>
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Gerado em Wed Sep 10 23:05:55 2008 para L2LB por&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>
